package com.yanqu.road.server.logic.activity.condition.normal;

import com.yanqu.road.entity.activity.ActivityConditionInfo;
import com.yanqu.road.entity.activity.ActivityInfo;
import com.yanqu.road.entity.config.goods.MallInfo;
import com.yanqu.road.entity.enums.eGamePlayerEventType;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.gameplayer.module.task.TaskModule;
import com.yanqu.road.server.logic.activity.BaseActivityData;
import com.yanqu.road.server.logic.activity.condition.BaseActivityCondition;
import com.yanqu.road.server.manger.activity.NormalActivityMgr;
import com.yanqu.road.server.manger.config.MallMgr;

import java.math.BigInteger;
import java.util.List;

/**
 * @author ：zfr
 * @date ：2021/10/8 10:37
 */
public class DailyDiscountOneKeyBuyCondition extends BaseActivityCondition {

    public DailyDiscountOneKeyBuyCondition(ActivityInfo activityInfo, ActivityConditionInfo activityConditionInfo, BaseActivityData baseActivityData) {
        super(activityInfo, activityConditionInfo, baseActivityData);
    }

    @Override
    public void addTrigger(GamePlayer player) {
        player.getModule(TaskModule.class).getGameEvent().addListener(eGamePlayerEventType.DailyDiscountOneKeyBuy.getValue(), handle);
    }

    @Override
    public void removeTrigger(GamePlayer player) {
        player.getModule(TaskModule.class).getGameEvent().removeListener(eGamePlayerEventType.DailyDiscountOneKeyBuy.getValue(), handle);
    }

    public boolean isCompleted(GamePlayer player) {
        return getValue().compareTo(activityConditionInfo.getParamList().get(3)) >= 0;
    }

    @Override
    protected void player_BoardLevelHandle(Object object) {
        int mallId = (int)object;
        if(mallId == activityConditionInfo.getParamList().get(2).intValue()){
            MallInfo mallInfo = MallMgr.getMallInfoByMallId(mallId);
            if (mallInfo != null) {
                List<ActivityConditionInfo> activityConditionInfoList = NormalActivityMgr.getActivityConditionInfoList(activityInfo.getActivityId());
                for (ActivityConditionInfo conditionInfo : activityConditionInfoList) {
                    if(conditionInfo.getType() == eGamePlayerEventType.RechargeItem.getValue()) {
                        player.notifyListener(eGamePlayerEventType.RechargeItem.getValue(), conditionInfo.getParamList().get(2).intValue());
                    }
                }
                setValue(BigInteger.ONE);
            }
        }
    }
}
